package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YxAvailaleTime;
import com.ruoyi.system.service.IYxAvailaleTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 可用时间段Controller
 * 
 * @author lingyu
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/system/availaleTime")
public class YxAvailaleTimeController extends BaseController
{
    @Autowired
    private IYxAvailaleTimeService yxAvailaleTimeService;

    /**
     * 查询可用时间段列表
     */
    @PreAuthorize("@ss.hasPermi('system:availaleTime:list')")
    @GetMapping("/list")
    public TableDataInfo list(YxAvailaleTime yxAvailaleTime)
    {
        startPage();
        List<YxAvailaleTime> list = yxAvailaleTimeService.selectYxAvailaleTimeList(yxAvailaleTime);
        return getDataTable(list);
    }

    /**
     * 导出可用时间段列表
     */
    @PreAuthorize("@ss.hasPermi('system:availaleTime:export')")
    @Log(title = "可用时间段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YxAvailaleTime yxAvailaleTime)
    {
        List<YxAvailaleTime> list = yxAvailaleTimeService.selectYxAvailaleTimeList(yxAvailaleTime);
        ExcelUtil<YxAvailaleTime> util = new ExcelUtil<YxAvailaleTime>(YxAvailaleTime.class);
        util.exportExcel(response, list, "可用时间段数据");
    }

    /**
     * 获取可用时间段详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:availaleTime:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yxAvailaleTimeService.selectYxAvailaleTimeById(id));
    }

    /**
     * 新增可用时间段
     */
    @PreAuthorize("@ss.hasPermi('system:availaleTime:add')")
    @Log(title = "可用时间段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YxAvailaleTime yxAvailaleTime)
    {
        return toAjax(yxAvailaleTimeService.insertYxAvailaleTime(yxAvailaleTime));
    }

    /**
     * 修改可用时间段
     */
    @PreAuthorize("@ss.hasPermi('system:availaleTime:edit')")
    @Log(title = "可用时间段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YxAvailaleTime yxAvailaleTime)
    {
        return toAjax(yxAvailaleTimeService.updateYxAvailaleTime(yxAvailaleTime));
    }

    /**
     * 删除可用时间段
     */
    @PreAuthorize("@ss.hasPermi('system:availaleTime:remove')")
    @Log(title = "可用时间段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yxAvailaleTimeService.deleteYxAvailaleTimeByIds(ids));
    }
}
